package cn.bingo.yunsj.controller;

import cn.bingo.yunsj.common.exception.EmException;
import cn.bingo.yunsj.common.exception.OwnException;
import cn.bingo.yunsj.common.result.Response;
import cn.bingo.yunsj.controller.model.SerachModel;
import cn.bingo.yunsj.domain.RpNotSend;
import cn.bingo.yunsj.service.SendAllService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api("发送与发送失败控制器")
@RequestMapping("/all")
@Controller
@CrossOrigin
public class AllSendController {

    @Autowired
    private SendAllService sendAllService;

    /**
     * 同时获取发送与发送失败，并合并加上状态后返回给前端
     */
    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("同时获取发送与发送失败，并合并加上状态后返回给前端")
    public Response all(){
        return sendAllService.all();
    }

    @RequestMapping(value = "/search",method = RequestMethod.GET)
    @ApiOperation("根据漏发人进行搜索")
    @ResponseBody
    public Response search(SerachModel serachModel){
        if(serachModel==null){
            throw new OwnException(EmException.PARAM_EXCPTION);
        }
        String start = "";
        if(serachModel.getStartTime()!=null) {
            start = serachModel.getStartTime().substring(0, serachModel.getStartTime().indexOf("T"));
        }
        String end = "";
        if(serachModel.getEndTime()!=null) {
            end = serachModel.getEndTime().substring(0, serachModel.getEndTime().indexOf("T"));
        }

        // 对后台数据库进行模糊搜索
        return sendAllService.search(serachModel, start, end);
    }

    /**
     * 查询发送成功与发送失败里面所有得贺卡类型
     */
    @RequestMapping(value = "/type",method = RequestMethod.GET)
    @ApiOperation("查询发送成功与发送失败里面所有得贺卡类型")
    @ResponseBody
    public Response getType(){
        return sendAllService.getType();
    }

}
